import request, { reqGetAboutUser } from "./request";
import manifestData from '@/manifest.json'

/** 使用微信返回的code进行登录 */
export const requestLoginByCode = (code: string) => {
  // 获取appid
  const accountInfo = uni.getAccountInfoSync()
  console.log('accountInfo', accountInfo)
  return request.getAboutUser("/xxl/oauth_user", { code, appid: accountInfo.miniProgram.appId });
}

/** 使用token获取用户信息 */
export const reqUserInfoByToken = () => {
  return request.getAboutUser("/xxl/getXxlUser", {
    appid: manifestData["mp-weixin"].appid
  });
}

/**
 * 微信手机号登录
 * @param code 授权手机号的code
 * @param parent_id 上级id
 */
export const reqLoginByPhone = (code: string, parentId: string = '') => {
  return request.getAboutUser("/xxl/wxPhoneLogin", { code, parent_id: parentId });
}

/**
 * 修改头像昵称
 * @param avatarPath 头像地址
 * @param name 昵称
 * @param invitorId 邀请人id
 */
export const reqUpdateAvatarAndName = (avatarPath: string, name: string, invitorId?: string) => {
  return reqGetAboutUser("/xxl/updateXxlUser", { wx_headimg: avatarPath, wx_name: name, inviter_id: invitorId || '' });
}

/**
 * 绑定支付宝
 * @param zfbAccount 支付宝账号（手机号）
 * @param zfbName 支付宝实名姓名
 */
export function bindAlipay(zfbAccount: string, zfbName: string) {
  return request.post('/VipPay/zfbBind', {
    zfbAccount,
    zfbName
  })
}

/**
 * 提现账户余额
 * @param money 提取的金额数量
 */
export function takeOutByAlipay(money: string) {
  return request.post('/VipPay/withdraw', {
    money
  })
}

/**
 * 用户提现明细
 */
export function takeOutList() {
  return request.post('/VipPay/withdrawList')
}

/**
 * 用户邀请的人数
 */
export function invitePersonList() {
  return request.post('/VipPay/inviteRecord')
}

